home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
CBGRX100.ARJ
/
CIRCLE.C
< prev
next >
Wrap
Text File
|
1992-04-10
|
4KB
|
167 lines
/**
** CIRCLE.C
**
** Copyright (C) 1992, Csaba Biegl
** 820 Stirrup Dr, Nashville, TN, 37221
** csaba@vuse.vanderbilt.edu
**
** This file is distributed under the terms listed in the document
** "copying.cb", available from the author at the address above.
** A copy of "copying.cb" should accompany this file; if not, a copy
** should be available from where this file was obtained. This file
** may not be distributed without a verbatim copy of "copying.cb".
** You should also have received a copy of the GNU General Public
** License along with this program (it is in the file "copying");
** if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
** Cambridge, MA 02139, USA.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**/
#include "grx.h"
#include "libgrx.h"
#include "clipping.h"
#define ulong unsigned long
static void drawellip(int xc,int yc,int xa,int ya,int c,int filled)
{
ulong sqr,dx2,xa2;
int x1,x2,y1,y2;
int dx,dy,dxprev;
int small;
MOUSE_FLAG;
if(xa < 0) xa = (-xa);
if(ya < 0) ya = (-ya);
x1 = xc - xa; y1 = yc - ya;
x2 = xc + xa; y2 = yc + ya;
CLIPBOXTEST(CURC,x1,y1,x2,y2);
MOUSE_BLOCK(CURC,x1,y1,x2,y2);
if(xa <= 1) {
if(xa > 0) {
dy = (int)((((ulong)ya * 7L) + 5L) / 10L);
y2 = yc + dy;
y1 = yc - dy;
GrVLine(xc-1,y1,y2,c);
GrVLine(xc+1,y1,y2,c);
}
if(filled || (xa == 0) || (y1 == y2))
GrVLine(xc,yc-ya,yc+ya,c);
else {
GrVLine(xc,yc-ya,y1,c);
GrVLine(xc,yc+ya,y2,c);
}
MOUSE_UNBLOCK();
return;
}
if(ya <= 1) {
if(ya > 0) {
dx = (int)((((ulong)xa * 7L) + 5L) / 10L);
x2 = xc + dx;
x1 = xc - dx;
GrHLine(x1,x2,yc-1,c);
GrHLine(x1,x2,yc+1,c);
}
if(filled || (ya == 0) || (x1 == x2))
GrHLine(xc-xa,xc+xa,yc,c);
else {
GrHLine(xc-xa,x1,yc,c);
GrHLine(x2,xc+xa,yc,c);
}
MOUSE_UNBLOCK();
return;
}
sqr = (ulong)(xa + 1) * (ulong)ya;
if(sqr < 65536L) {
small = TRUE;
dx2 = (ulong)xa * (ulong)ya;
sqr *= dx2;
xa2 = (ulong)xa * (ulong)(xa + 1);
}
else {
small = FALSE;
dx2 = (ulong)ya;
sqr = (ulong)ya * (ulong)(ya + 1);
}
dx = dxprev = xa;
dy = 0;
if(filled)
GrHLine(xc-dx,xc+dx,yc,c);
else {
GrPlot(xc-dx,yc,c);
GrPlot(xc+dx,yc,c);
}
while(++dy <= ya) {
if(small) {
if(dx) {
sqr -= (ulong)(dy + dy - 1) * xa2;
dx2 = (dx2 + sqr/dx2) / 2L;
dx = (int)(dx2 / (ulong)ya);
}
}
else {
if(dx) {
sqr -= (ulong)(dy + dy - 1);
dx2 = (dx2 + sqr/dx2) / 2L;
dx = (int)((dx2 * (ulong)xa) / (ulong)ya);
}
}
x1 = xc - dx;
x2 = xc + dx;
y1 = yc - dy;
y2 = yc + dy;
if(!filled && ((dxprev - dx) > 1)) {
if((dxprev - dx) > 2) {
GrLine(xc-dxprev+1,y1+1,x1-1,y1,c);
GrLine(x2+1,y1,xc+dxprev-1,y1+1,c);
GrLine(xc-dxprev+1,y2-1,x1-1,y2,c);
GrLine(x2+1,y2,xc+dxprev-1,y2-1,c);
}
else {
GrPlot(x1-1,y1+1,c);
GrPlot(x2+1,y1+1,c);
GrPlot(x1-1,y2-1,c);
GrPlot(x2+1,y2-1,c);
}
}
dxprev = dx;
if(filled || (dy == ya)) {
GrHLine(x1,x2,y1,c);
GrHLine(x1,x2,y2,c);
continue;
}
else {
GrPlot(x1,y1,c);
GrPlot(x2,y1,c);
GrPlot(x1,y2,c);
GrPlot(x2,y2,c);
}
}
MOUSE_UNBLOCK();
}
void GrCircle(int xc,int yc,int r,int c)
{
drawellip(xc,yc,r,r,c,FALSE);
}
void GrFilledCircle(int xc,int yc,int r,int c)
{
drawellip(xc,yc,r,r,c,TRUE);
}
void GrEllipse(int xc,int yc,int xa,int ya,int c)
{
drawellip(xc,yc,xa,ya,c,FALSE);
}
void GrFilledEllipse(int xc,int yc,int xa,int ya,int c)
{
drawellip(xc,yc,xa,ya,c,TRUE);
}